package main

import (
	"encoding/json"
	"fmt"
	"log"
	"mscoin-common/kafkaTest/kafkaTest"
)

/*
*
启动消费者
*/

type Data struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	client := kafkaTest.NewKafkaClient(kafkaTest.KafkaConfig{
		Addr:          "192.168.200.161:9092",
		WriteCap:      100,
		ReadCap:       100,
		ConsumerGroup: "exchange-consumer",
	})
	//消费消息
	client.StartRead("test") //开启读的操作
	for {
		//必须不停的消费数据
		read := client.Read()
		key := string(read.Key)
		fmt.Println(key)
		m := &Data{}
		err := json.Unmarshal(read.Data, m)
		if err != nil {
			log.Print("解析失败")
		}
		fmt.Println("获取消费数据:", m)
	}

}
